export type CacheType = 'memory' | 'session' | 'local' | 'db'
export type IObject = Record<string, any>
/**请求功能控制 */
export interface Ictr {
  /**防抖 */
  debounce?: boolean
  /**缓存 */
  dataCache?: boolean
  /**缓存类型 */
  cacheType?: CacheType
  /**缓存过期时间 */
  cacheExpire?: number,
  /**是否显示错误提示 */
  isErrorTip?: boolean
  /**是否显示成功提示 */
  isOkTip?: boolean
  /**是否返回不经过处理的原始值 */
  isOrigina?: boolean
}
/**请求配置 */
export interface IOptions {
  baseURL?: string
  method?: string
  timeout?: number
  headers?: HeadersInit
  data?: string | FormData
}
/**返回类型 */
type IStatusType = 'pending' | 'success' | 'error'
export interface IResponse {
  status: IStatusType
  data: any
}
interface IHookrequestData {
  url: string
  options: IOptions
  ctr: Ictr
}
interface IHookresponseData extends IHookrequestData {
  /**原始返回数据-该字段不可修改 */
  originalData: IResponse
  /**请求返回值 */
  result: any
}
/**钩子函数中断返回 */
export interface IHookBreakData {
  breakName: string
  data: any
}

type IHookBreakDataOrVoid = IOptions | IHookBreakData | void
/**请求前钩子函数 */
export interface IRequestHook {
  (IHookrequestData: IHookrequestData): IHookBreakDataOrVoid | Promise<IHookBreakDataOrVoid>
}
/**请求返回钩子函数 */
export interface IResponseHook {
  (IHookresponseData: IHookresponseData): any | Promise<any>
}
/**钩子函数 */
export interface IHook {
  request: IRequestHook
  response: IResponseHook
}
export interface IAdapter<T> {
  (url: string, options: IOptions): Promise<T>
}
